// 头部导航列表数据
import { findAllCategory } from "@/api/category";

export default {
  namespaced: true,
  state: () => {
    return {
      list: [
        { name: "居家" },
        { name: "美食" },
        { name: "服饰" },
        { name: "母婴" },
        { name: "个护" },
        { name: "严选" },
        { name: "数码" },
        { name: "运动" },
        { name: "杂货" },
      ],
    };
  },
  // 加载数据成功后需要修改list所以需要mutations函数
  mutations: {
    setList(state, payload) {
      state.list = payload;
    },
  },
  // 需要向后台加载数据，所以需要actions函数获取数据
  actions: {
    async getList({ commit }) {
      const { result } = await findAllCategory();
      // 获取数据成功，提交mutations进行数据修改
      commit("setList", result);
    },
  },
};
